package com.example.controller;

import com.example.consts.RbmConsts;
import com.example.pojo.dto.CollectDTO;
import com.example.pojo.dto.DriverDTO;
import com.example.pojo.dto.UserInfoDTO;
import com.example.pojo.entity.Collect;
import com.example.service.CollectService;
import com.example.service.DriverService;
import com.example.vo.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 本文来演示
 *
 * @author 赵建云
 * @create 2023/10/10
 */
@RestController
@RequestMapping("collect")
public class CollectController {
    @Autowired
    private CollectService collectService;
    @Autowired
    private DriverService driverService;
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @PostMapping("search")
    public Result searchCollect(Integer jsId,Integer posId){
        Collect collect = collectService.searchCollect(jsId,posId);
        String click = jsId+","+posId;
        rabbitTemplate.convertAndSend(RbmConsts.ROOTING_EX,RbmConsts.ROOTING_DH_CLICK_RK,click);
        if (collect!=null){
            return new Result(200,"已经被收藏");
        }else {
            return new Result(500,"还没有被收藏");
        }

    }
    @PostMapping("add")
    public Result collectAdd(Integer jsId,Integer posId){

        int count = collectService.collectSave(jsId, posId);
        if (count==0){
            return new Result(500,"存储失败");
        }else {
            return new Result(200,"存储成功");
        }
    }

    @PostMapping("delete")
    public Result collectDelete(Integer jsId,Integer posId){
        int count = collectService.collectDelete(jsId, posId);
        if (count==0){
            return new Result(200,"取消失败");
        }else {
            return new Result(200,"取消成功");
        }
    }
    @PostMapping ("total")
    public Result jobFromChatTotal(Integer jsId){
        System.err.println(jsId);
        List<CollectDTO> list = collectService.findTotal(jsId);

        if (null!=list){
            return new Result(200,"感兴趣",list.size());
        }else {
            return new Result(500,"暂时未有关注的职位，建议尝试查看推荐职位");
        }

    }
    @PostMapping ("jobfromchat")
    public Result jobFromChat(Integer page,Integer limit,Integer jsId){
        System.err.println(jsId);
        PageInfo<CollectDTO> pageInfo = collectService.findById(page,limit,jsId);

        if (null!=pageInfo){
            return new Result(200,"感兴趣",pageInfo);
        }else {
            return new Result(500,"暂时未有关注的职位，建议尝试查看推荐职位");
        }

    }
    @PostMapping("userInfo")
    public Result findUserInfo(Integer jsId){
        System.out.println("=collect/userInfo=");
        System.out.println(jsId);
        UserInfoDTO userInfoDTO = collectService.findUserInfo(jsId);
        if (userInfoDTO!=null){
            return new Result(200,"个人信息",userInfoDTO);
        }else {
            return new Result(500,"查无此人");
        }

    }
    @PostMapping("num")
    public Result num(Integer jsId){
        DriverDTO driverDTO = driverService.findJobFromChat(jsId);
        return new Result(200,"各个数量",driverDTO);
    }

    @PostMapping("addedTotal")
    public Result addedTotal(Integer jsId){
        List<CollectDTO> list = collectService.messageBySid(jsId);

        if (null!=list){
            return new Result(200,"沟通过",list.size());
        }else {
            return new Result(500,"暂时未有关注的职位，建议尝试查看推荐职位");
        }
    }
    @PostMapping("added")
    public Result added(Integer page,Integer limit,Integer jsId){

        PageInfo<CollectDTO> pageInfo = collectService.messageFindBySid(page,limit,jsId);

        if (null!=pageInfo){
            return new Result(200,"沟通过",pageInfo);
        }else {
            return new Result(500,"暂时未有关注的职位，建议尝试查看推荐职位");
        }
    }

    @PostMapping("submitTotal")
    public Result submitTotal(Integer jsId){
        List<CollectDTO> list = collectService.submitByJsId(jsId);
        if (null!=list){
            return new Result(200,"已投递",list.size());
        }else {
            return new Result(500,"暂时未有关注的职位，建议尝试查看推荐职位");
        }
    }
    @PostMapping("submit")
    public Result submit(Integer page,Integer limit,Integer jsId){
        PageInfo<CollectDTO> pageInfo = collectService.submitFindBySid(page,limit,jsId);

        if (null!=pageInfo){
            return new Result(200,"已投递",pageInfo);
        }else {
            return new Result(500,"暂时未有关注的职位，建议尝试查看推荐职位");
        }
    }

    @PostMapping("interviewTotal")
    public Result interviewTotal(Integer jsId){
        List<CollectDTO> list = collectService.interviewByJsId(jsId);
        if (null!=list){
            return new Result(200,"面试",list.size());
        }else {
            return new Result(500,"暂时未有关注的职位，建议尝试查看推荐职位");
        }
    }
    @PostMapping("interview")
    public Result interview(Integer page,Integer limit,Integer jsId){
        PageInfo<CollectDTO> pageInfo = collectService.interviewFindBySid(page,limit,jsId);

        if (null!=pageInfo){
            return new Result(200,"面试",pageInfo);
        }else {
            return new Result(500,"暂时未有关注的职位，建议尝试查看推荐职位");
        }
    }
}
